import requests
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

from pages.login_page import LoginPage
from utils.get_driver import get_driver


class BaseTestcase(object):

    def setup(self):
        self.driver = get_driver()
        self.driver.implicitly_wait(20)

    def login_for_each_test(driver, url, email_name, passwd, site_id):
        login_for_all_test = LoginPage(driver, url, email_name, passwd, site_id)
        try:
            # login_for_all_test.goto_page()
            # time.sleep(5)
            login_for_all_test.login()
            wait = WebDriverWait(driver, 10, 0.5)
            ele_dashboard_title = wait.until(EC.presence_of_all_elements_located((By.ID, "undefined-title")))
        except Exception as e:
            print(e)

    def teardown(self):
        self.driver.quit()
